package demo2;

public class LeetCode3 {
    public int lengthOfLongestSubstring(String s) {
        int[] hash = new int[128];
        char[] arr = s.toCharArray();
        int n = arr.length, len = 0;
        for (int left = 0, right = 0; right < n; right++) {
            hash[arr[right]]++;
            while (hash[arr[right]] > 1) hash[arr[left++]]--;
            len = Math.max(len, right - left + 1);
        }
        return len;
    }
}
